package com.top.ruizhong.main.cate

import android.widget.ImageView
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.module.lemlin.base.BaseAbstractFragment
import com.module.lemlin.custom.SpacingItemDecoration
import com.top.ruizhong.R
import com.top.ruizhong.entity.Category
import com.top.ruizhong.main.video.VideoCateActivity
import kotlinx.android.synthetic.main.fragment_category_video.*

class CateVideoFragment : BaseAbstractFragment() {

    companion object {
        fun newInstance(): CateVideoFragment {
            return CateVideoFragment()
        }
    }


    private val cateIconAdapter = object :
        BaseQuickAdapter<Category, BaseViewHolder>(R.layout.item_category_icon) {
        override fun convert(holder: BaseViewHolder, item: Category) {
            holder.setText(R.id.tvCategoryTitle, item.title)
            holder.getView<ImageView>(R.id.ivCategoryIcon).setImageResource(item.icon)
        }
    }

    override val layoutResId: Int
        get() = R.layout.fragment_category_video

    override fun initView() {

        rvCategoryBody.apply {
            val decoration = SpacingItemDecoration(
                nSpan = 3, vGap = ConvertUtils.dp2px((30f)), hGap = ConvertUtils.dp2px((0f))
            )
            addItemDecoration(decoration)
        }.adapter = cateIconAdapter.apply {

            val category1: MutableList<Category> = mutableListOf(
                Category(R.mipmap.ic_17233, "娱乐时尚"),
                Category(R.mipmap.ic_17228, "个人生活"),
                Category(R.mipmap.ic_17226, "美食尝鲜"),
                Category(R.mipmap.ic_17235, "运动专区"),
                Category(R.mipmap.ic_17229, "歌声悠扬")
            )
            cateIconAdapter.setNewInstance(category1)
        }

        cateIconAdapter.setOnItemClickListener { _, _, _ ->
            VideoCateActivity.open(requireActivity())
        }
    }

    override fun initData() {


    }
}